package com.enjoyor.soa.traffic.rest.tsms.dubbo.impl;

import org.springframework.stereotype.Component;
import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.dto.tsms.CommonRouteDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tsms.IDubboCommonRouteService;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.ICommonRouteConsumeService;
import com.enjoyor.soa.traffic.util.helper.GeomtryHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import oracle.spatial.geometry.JGeometry;

@Component
public class CommonRouteConsumService implements ICommonRouteConsumeService{

	@Reference(version = "1.0.0", timeout = 10000)
    //@Reference(version = "1.0.0", timeout = 10000, url="dubbo://192.168.56.8:21241")
	private IDubboCommonRouteService iDubboCommonRouteService;
	@Override
	public ResultPojo getCommonRoutePage(Page page, String commonRouteId, String commonRouteName,String routeStartPlace, String routeTargetPlace) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iDubboCommonRouteService.getCommonRoutePage(page, commonRouteId, commonRouteName, routeStartPlace, routeTargetPlace);
		return resultPojo;
	}

	@Override
	public ResultPojo getCommonRouteList(String commonRouteId, String commonRouteName, String routeStartPlace,String routeTargetPlace) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iDubboCommonRouteService.getCommonRouteList(commonRouteId, commonRouteName, routeStartPlace, routeTargetPlace);
		return resultPojo;
	}

	@Override
	public ResultPojo addCommonRoute(CommonRouteDto commonRouteDto,String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		String strArea = commonRouteDto.getStrArea();
		JGeometry jGeometry = GeomtryHelper.getGeomWithGson(strArea);
	    commonRouteDto.setRouteGeo(jGeometry);
		resultPojo = iDubboCommonRouteService.addCommonRoute(commonRouteDto, personName);
		return resultPojo;
	}

	@Override
	public ResultPojo editCommonRoute(CommonRouteDto commonRouteDto,String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		String strArea = commonRouteDto.getStrArea();
		JGeometry jGeometry = GeomtryHelper.getGeomWithGson(strArea);
	    commonRouteDto.setRouteGeo(jGeometry);
		resultPojo = iDubboCommonRouteService.editCommonRoute(commonRouteDto, personName);
		return resultPojo;
	}

	@Override
	public ResultPojo deleteCommonRoute(String commonRouteId,String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iDubboCommonRouteService.deleteCommonRoute(commonRouteId, personName);
		return resultPojo;
	}

}
